package com.lekang.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lekang.common.annotation.Log;
import com.lekang.common.core.controller.BaseController;
import com.lekang.common.core.domain.AjaxResult;
import com.lekang.common.enums.BusinessType;
import com.lekang.domain.AppointmentRegistration;
import com.lekang.service.IAppointmentRegistrationService;
import com.lekang.common.utils.poi.ExcelUtil;
import com.lekang.common.core.page.TableDataInfo;

/**
 * 预约登记Controller
 * 
 * @author chengbingzhen
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/commanage/yuyue")
public class AppointmentRegistrationController extends BaseController
{
    @Autowired
    private IAppointmentRegistrationService appointmentRegistrationService;
    /**
     * 查询预约登记列表
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppointmentRegistration appointmentRegistration)
    {
        startPage();
        List<AppointmentRegistration> list = appointmentRegistrationService.selectAppointmentRegistrationList(appointmentRegistration);
        return getDataTable(list);
    }
    /**
     * 查询预约登记列表（微信用户）
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:list')")
    @GetMapping("/list/wxuser")
    public TableDataInfo listByWxUser(AppointmentRegistration appointmentRegistration)
    {
        List<AppointmentRegistration> list = appointmentRegistrationService.selectAppointmentRegistrationListByWxUser(appointmentRegistration);
        return getDataTable(list);
    }

    /**
     * 导出预约登记列表
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:export')")
    @Log(title = "预约登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppointmentRegistration appointmentRegistration)
    {
        List<AppointmentRegistration> list = appointmentRegistrationService.selectAppointmentRegistrationList(appointmentRegistration);
        ExcelUtil<AppointmentRegistration> util = new ExcelUtil<AppointmentRegistration>(AppointmentRegistration.class);
        util.exportExcel(response, list, "预约登记数据");
    }

    /**
     * 获取预约登记详细信息
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appointmentRegistrationService.selectAppointmentRegistrationById(id));
    }

    /**
     * 新增预约登记
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:add')")
    @Log(title = "预约登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppointmentRegistration appointmentRegistration)
    {
        return toAjax(appointmentRegistrationService.insertAppointmentRegistration(appointmentRegistration));
    }

    /**
     * 修改预约登记
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:edit')")
    @Log(title = "预约登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppointmentRegistration appointmentRegistration)
    {
        return toAjax(appointmentRegistrationService.updateAppointmentRegistration(appointmentRegistration));
    }

    /**
     * 删除预约登记
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:remove')")
    @Log(title = "预约登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appointmentRegistrationService.deleteAppointmentRegistrationByIds(ids));
    }

     /**
     * 按wx_user_id统计当天（create_time）内appointment_type为“参观预约”的数据条数
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:query')")
    @GetMapping("/count/visit/{wxUserId}")
    public AjaxResult selectTodayVisitCountByWxUserId(@PathVariable("wxUserId") Long wxUserId)
    {
        return success(appointmentRegistrationService.selectTodayVisitCountByWxUserId(wxUserId));
    }

     /**
     * 按wx_user_id统计当天（create_time）内appointment_type为“探访预约”的数据条数
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:query')")
    @GetMapping("/count/seek/{wxUserId}")
    public AjaxResult selectTodaySeekCountByWxUserId(@PathVariable("wxUserId") Long wxUserId)
    {
        return success(appointmentRegistrationService.selectTodaySeekCountByWxUserId(wxUserId));
    }

     /**
     * 按wx_user_id统计当天（create_time）内status为“已取消”的数据条数
     */
    @PreAuthorize("@ss.hasPermi('commanage:yuyue:query')")
    @GetMapping("/count/canceled/{wxUserId}")
    public AjaxResult selectTodayCanceledCountByWxUserId(@PathVariable("wxUserId") Long wxUserId)
    {
        return success(appointmentRegistrationService.selectTodayCanceledCountByWxUserId(wxUserId));
    }
}
